package com.cml.client.application;

import com.cml.client.common.config.Configuration;
import com.cml.client.common.context.ApplicationContext;
import com.cml.client.domain.service.ServiceInstanceService;
import com.cml.client.infrastructure.NetworkManager;
import com.cml.common.dto.entity.ServiceInstance;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.util.List;

/**
 * 姓名：陈茂林
 * 时间：2023/10/16 13:38
 * 描述：
 */
public class ServiceInstanceAppliction {
    private Logger logger = Logger.getLogger(ServiceInstanceAppliction.class);

    private ServiceInstanceService serviceInstanceService;

    public void start(String fileName){
        try {
            Configuration.getInstance().parse(fileName);
            ApplicationContext applicationContext =new ApplicationContext.Builder()
                    .build();
            serviceInstanceService =applicationContext.getServiceInstanceService();
            serviceInstanceService.start();
        } catch (IOException e) {
            logger.error("配置文件解析出错");
            logger.error(e);
            System.exit(0);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e);
            System.exit(0);
        }
    }

    public void subscribe(String serviceName)throws Exception {
        serviceInstanceService.subscribe(serviceName);
    }

    public List<ServiceInstance> getServiceInstanceList(String serviceName){
        return serviceInstanceService.getServiceInstanceList(serviceName);
    }

}
